/**
 * 
 */
package com.zastoupil.pgc.blueprint_pattern.xml.compile.bluescript;

/**
 * Enumerated type that represents the lexical structure for the Bluescript
 * scripting language. The regexes used to define this lexical structure were
 * taken directly from the Java SE 1.7 language specification
 * 
 * @author Peter Zastoupil
 * 
 */
public enum BluescriptLexicalStructure {
	
	// Decimal Numeral Grammar
	ZERO("0"),
	NONZERO_DIGIT("[1-9]"),
	DIGIT("[" + ZERO + NONZERO_DIGIT + "]"),
	UNDERSCORE("_"),
	UNDERSCORES(UNDERSCORE + "+"),
	DIGIT_OR_UNDERSCORE("[" + DIGIT + UNDERSCORE + "]"),
	DIGITS_AND_UNDERSCORES(DIGIT_OR_UNDERSCORE + "+"),
	DIGITS(DIGIT + "|" + DIGIT + DIGITS_AND_UNDERSCORES + "?" + DIGIT),
	DECIMAL_NUMERAL(ZERO + "|" + NONZERO_DIGIT + DIGITS + "?" + "|" + NONZERO_DIGIT + UNDERSCORES + DIGITS),
	
	// Hex Numeral Grammar
	HEX_INDICATOR("[xX]"),
	HEX_DIGIT("[0-9a-fA-F]"),
	HEX_DIGIT_OR_UNDERSCORE("[" + HEX_DIGIT + UNDERSCORE + "]"),
	HEX_DIGITS_AND_UNDERSCORES(HEX_DIGIT_OR_UNDERSCORE + "+"),
	HEX_DIGITS(HEX_DIGIT + "|" + HEX_DIGIT + HEX_DIGITS_AND_UNDERSCORES + "?" + HEX_DIGIT),
	HEX_NUMERAL("" + ZERO + HEX_INDICATOR + HEX_DIGITS),
	
	// Octal Numeral Grammar
	OCTAL_DIGIT("[0-7]"),
	OCTAL_DIGIT_OR_UNDERSCORE("[" + OCTAL_DIGIT + UNDERSCORE + "]"),
	OCTAL_DIGITS_AND_UNDERSCORES(OCTAL_DIGIT_OR_UNDERSCORE + "+"),
	OCTAL_DIGITS(OCTAL_DIGIT + "|" + OCTAL_DIGIT + OCTAL_DIGITS_AND_UNDERSCORES + "?" + OCTAL_DIGIT),
	OCTAL_NUMERAL("" + ZERO + OCTAL_DIGITS + "|" + ZERO + UNDERSCORES + OCTAL_DIGITS),
	
	// Binary Numeral Grammar
	BINARY_INDICATOR("[bB]"),
	BINARY_DIGIT("[01]"),
	BINARY_DIGIT_OR_UNDERSCORE("[" + BINARY_DIGIT + UNDERSCORE + "]"),
	BINARY_DIGITS_AND_UNDERSCORES(BINARY_DIGIT_OR_UNDERSCORE + "+"),
	BINARY_DIGITS(BINARY_DIGIT + "|" + BINARY_DIGIT + BINARY_DIGITS_AND_UNDERSCORES + "?" + BINARY_DIGIT),
	BINARY_NUMERAL("" + ZERO + BINARY_INDICATOR + BINARY_DIGITS),
	
	// Integer Literal Grammar
	INTEGER_TYPE_SUFFIX("[lL]"),
	DECIMAL_INTEGER_LITERAL("" + DECIMAL_NUMERAL + INTEGER_TYPE_SUFFIX + "?"),
	HEX_INTEGER_LITERAL("" + HEX_NUMERAL + INTEGER_TYPE_SUFFIX + "?"),
	OCTAL_INTEGER_LITERAL("" + OCTAL_NUMERAL + INTEGER_TYPE_SUFFIX + "?"),
	BINARY_INTEGER_LITERAL("" + BINARY_NUMERAL + INTEGER_TYPE_SUFFIX + "?"),
	INTEGER_LITERAL(DECIMAL_INTEGER_LITERAL + "|" + HEX_INTEGER_LITERAL + "|" + OCTAL_INTEGER_LITERAL + "|" + BINARY_INTEGER_LITERAL),
	
	// Decimal Floating Point Literal Grammar
	SIGN("\\+|-"),
	SIGNED_INTEGER(SIGN + "?" + DIGITS),
	EXPONENT_INDICATOR("[eE]"),
	EXPONENT_PART("" + EXPONENT_INDICATOR + SIGNED_INTEGER),
	POINT("[.]"),
	FLOAT_TYPE_SUFFIX("[fFdD]"),
	DECIMAL_FLOATING_POINT_LITERAL("" + DIGITS + POINT + DIGITS + "?" + EXPONENT_PART + "?" + FLOAT_TYPE_SUFFIX + "|" + POINT + DIGITS + EXPONENT_PART + "?" + FLOAT_TYPE_SUFFIX + "?" + "|" + DIGITS + EXPONENT_PART + FLOAT_TYPE_SUFFIX + "?" + "|" + DIGITS + EXPONENT_PART + "?" + FLOAT_TYPE_SUFFIX),
	
	// Hexadecimal Floating Point Literal Grammar
	BINARY_EXPONENT_INDICATOR("[pP]"),
	BINARY_EXPONENT("" + BINARY_EXPONENT_INDICATOR + SIGNED_INTEGER),
	HEX_SIGNIFICAND(HEX_NUMERAL + "|" + HEX_NUMERAL + POINT + "|" + ZERO + HEX_INDICATOR + HEX_DIGITS + "?" + POINT + HEX_DIGITS),
	HEXADECIMAL_FLOATING_POINT_LITERAL("" + HEX_SIGNIFICAND + BINARY_EXPONENT + FLOAT_TYPE_SUFFIX + "?"),
	
	FLOATING_POINT_LITERAL(DECIMAL_FLOATING_POINT_LITERAL + "|" + HEXADECIMAL_FLOATING_POINT_LITERAL),
	
	// Boolean Literal Grammar
	BOOLEAN_LITERAL("true|false"),
	
	// Escape Sequence Grammar
	ESCAPE_CHARACTER("\\"),
	ESCAPE_BACKSPACE(ESCAPE_CHARACTER + "[b]"),
	ESCAPE_HORIZONTAL_TAB(ESCAPE_CHARACTER + "[t]"),
	ESCAPE_LINE_FEED(ESCAPE_CHARACTER + "[n]"),
	ESCAPE_FORM_FEED(ESCAPE_CHARACTER + "[f]"),
	ESCAPE_CARRIAGE_RETURN(ESCAPE_CHARACTER + "[r]"),
	ESCAPE_DOUBLE_QUOTE(ESCAPE_CHARACTER + "[\"]"),
	ESCAPE_SINGLE_QUOTE(ESCAPE_CHARACTER + "[\']"),
	ESCAPE_BACKSLASH(ESCAPE_CHARACTER + "[\\]"),
	OCTAL_ESCAPE("" + ESCAPE_CHARACTER + OCTAL_DIGIT + "|" + ESCAPE_CHARACTER + OCTAL_DIGIT + OCTAL_DIGIT + "|" + ESCAPE_CHARACTER + "[0-3]" + OCTAL_DIGIT + OCTAL_DIGIT),
	ESCAPE_SEQUENCE("[" + ESCAPE_BACKSPACE + ESCAPE_HORIZONTAL_TAB + ESCAPE_LINE_FEED + ESCAPE_FORM_FEED + ESCAPE_CARRIAGE_RETURN + ESCAPE_DOUBLE_QUOTE + ESCAPE_SINGLE_QUOTE + ESCAPE_BACKSLASH + OCTAL_ESCAPE + "]"),
	
	// Character Literal Grammar
	SINGLE_CHARACTER("[^\\\\\\']"),
	CHARACTER_LITERAL("\'" + ESCAPE_SEQUENCE + "\'" + "|" + "\'" + SINGLE_CHARACTER + "\'"),
	
	// String Literal Grammar
	STRING_CHARACTER("[^\\\\\\\"]" + "|" + ESCAPE_SEQUENCE),
	STRING_CHARACTERS(STRING_CHARACTER + "+"),
	STRING_LITERAL("\"" + STRING_CHARACTERS + "?" + "\"");
	
	private String literalPattern;
	
	BluescriptLexicalStructure(String literalPattern){
		this.literalPattern = literalPattern;
	}
	
	@Override
	public String toString() {
		return "(" + this.literalPattern + ")";
	}

}
